<?php
/*
 * Copyright 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class FCBaseGadget {

  protected $params;
  protected $method = 'renderOpenSocialGadget';
  protected $module;
  protected $skin_params = array();
  protected $view_params = array();
  protected $gadget_params = array();
  public function __construct($mod_params){
    $this->params = $mod_params;
    $this->skin_params = $this->getSkin();
    $this->module = JModuleHelper::getModule('friendconnect', '');
    $this->gadget_params = array('id'=> $this->getId(),'site'=>$this->params->get('fc_site_id'));
  }

  private function getSkin(){
    $skin = array();
    $skin['BORDER_COLOR']					= $this->params->get('border_color', "");
    $skin['ENDCAP_BG_COLOR']				= $this->params->get('endcap_background', "");
    $skin['ENDCAP_TEXT_COLOR']				= $this->params->get('endcap_text', "");
    $skin['ENDCAP_LINK_COLOR']				= $this->params->get('endcap_links', "");
    $skin['ALTERNATE_BG_COLOR']				= $this->params->get('alternate_background', "");
    $skin['CONTENT_BG_COLOR']				= $this->params->get('content_background', "");
    $skin['CONTENT_LINK_COLOR']				= $this->params->get('content_links', "");
    $skin['CONTENT_TEXT_COLOR']				= $this->params->get('content_text', "");
    $skin['CONTENT_SECONDARY_LINK_COLOR']	= $this->params->get('content_secondary_links', "");
    $skin['CONTENT_SECONDARY_TEXT_COLOR']	= $this->params->get('content_secondary_text', "");
    $skin['CONTENT_HEADLINE_COLOR']			= $this->params->get('content_headlines', "");
    $skin['DEFAULT_COMMENT_TEXT']			= $this->params->get('default_comment_text', "");
    $skin['HEADER_TEXT']					= $this->params->get('header_text', "");
    return $skin;
  }
  
  protected function setSkinParams(Array $skin_params) {
    $this->skin_params = array_merge($this->skin_params, $skin_params);
  }
  
  protected function setViewParams($view_params) {
    $this->view_params = $view_params;
  }
  
  protected function getId() {
    return $this->params->get('gadget_to_render').'_'.$this->module->id 
      . $this->module->position;
  }
  
  protected function setGadgetParams(Array $gadget_params) {
    $this->gadget_params = array_merge($this->gadget_params, $gadget_params);
  }
  public function render(){
    $div_id = $this->getId();
    $skin = $div_id . '_skin';
    if($this->view_params) {
      $this->gadget_params['view-params'] = $this->view_params;
    }
    ?>
    <!-- 
    <friendconnect_gadget> 
    -->
    <div id=<?php echo $div_id?>> </div>
    <script type="text/javascript">
    <?php echo $skin?> = <?php echo json_encode($this->skin_params)?>;
    google.friendconnect.container.setParentUrl('/');
    google.friendconnect.container.<?php echo $this->method?>(
		<?php echo json_encode($this->gadget_params)?>, <?php echo $skin?>
    );
    </script>
    <!-- 
    </friendconnect_gadget> 
    -->
    <?php
  }
}